package models.sys;

import com.alibaba.fastjson.JSONObject;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * Created by zqx on 16/5/16.
 */

@Entity
@Table(name = "tb_admin_user")
public class AdminUser extends SystemModel {

    public String username;
    public String password;
    public String salt;
    public String realname;

    @Column(columnDefinition = "INT default 1")   //默认值为1(未锁定),0为锁定
    public Integer enabled;

    @ManyToOne
    public AdminRole role;

    public static AdminUser findByInfo(JSONObject info) {
        if (info == null)
            return null;
        return AdminUser.find("byUsernameAndPassword",info.getString("username"),info.getString("password")).first();
    }

    public JSONObject getInfo(){
        JSONObject info = this.toJSON();
        info.remove("password");
        info.remove("salt");
        info.remove("role");
        return info;
    }
}
